package com.cysyz.mylib.commonservice.treeservice.impl;

import java.util.List;

import javax.annotation.Resource;

import com.cysyz.mylib.commonservice.treeservice.TreeService;
import com.cysyz.mylib.commonservice.treeservice.support.TreeAble;
import com.cysyz.mylib.commonservice.treeservice.support.TreeAbleService;

public class TreeServiceImpl implements TreeService{
	@Resource
	private TreeAbleService treeAbleService;
	
	@Override
	public List<TreeAble> findAllChilds(Integer parentPk, int nowLevel, int totalLevel, List<TreeAble> result) {
		
		List<TreeAble> findChildByParent = treeAbleService.findChildByParent(parentPk);
		
		result.addAll(findChildByParent);
		
		++ nowLevel;
		
		if (nowLevel < totalLevel) {
			for (TreeAble treeAble : findChildByParent) {
				this.findAllChilds(treeAble.getPk(), nowLevel, totalLevel, result);
			}
		}
		
		return result;
	}
}
